/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Bean;

import DataBase.Koneksi;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author ZempoX
 */
public class Login {

    private String Username;
    private String Password;

    public Login(String Username, String Password) {
        this.Username = Username;
        this.Password = Password;
    }

    public String getUsername() {
        return Username;
    }

    public void setUsername(String Username) {
        this.Username = Username;
    }

    public String getPassword() {
        return Password;
    }

    public void setPassword(String Password) {
        this.Password = Password;
    }

    public boolean cekLogin(Login lg) {
        boolean status = false;
        Connection con = Koneksi.open();
        Statement st = null;
        try {
            st = con.createStatement();
        } catch (SQLException ex) {
            Logger.getLogger(Login.class.getName()).log(Level.SEVERE, null, ex);
        }
        String sql = "select * from LOGIN";
        ResultSet rs = null;
        try {
            rs = st.executeQuery(sql);
        } catch (SQLException ex) {
            Logger.getLogger(Login.class.getName()).log(Level.SEVERE, null, ex);
        }
        String user = lg.getUsername();
        String pass = lg.getPassword();
        try {
            while (rs.next()) {
                if ((user == null ? rs.getString("USERNAME") == null : user.equals(rs.getString("USERNAME"))) && (pass == null ? rs.getString("PASSWORD") == null : pass.equals(rs.getString("PASSWORD")))) {
                    status = true;
                    break;
                } else {
                    status = false;
                }
            }
        } catch (SQLException ex) {
            Logger.getLogger(Login.class.getName()).log(Level.SEVERE, null, ex);
        }
        return status;
    }
}
